home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / vs / browser / cpb10eb.exe / DATA.Z / doll.java < prev    next >
Text File  |  1996-09-25  |  1KB  |  53 lines

  1. //
  2. // doll.java
  3. //    click the parts of the doll to change color
  4. //
  5. // (c) Copyright 1996 Sony Corporation. All rights reserved.
  6.  
  7. import vrml.*;
  8. import vrml.field.*;
  9. import vrml.node.*;
  10. import java.util.*;
  11.  
  12. public class doll extends Script {
  13.     final int PARTS_MAX = 18;
  14.     SFColor mat[] = new SFColor[ PARTS_MAX ];
  15.     SFInt32 no[] = new SFInt32 [ PARTS_MAX ];
  16.     SFNode node;
  17.     String str;
  18.     SFColor color;
  19.     SFInt32 colorno;
  20.  
  21.     public void processEvent(Event e){
  22. //        System.out.println( "event" + e.getName());
  23.  
  24.     String str = e.getName();
  25.     if( str.startsWith( "clicked" )){
  26.         Integer ii = new Integer (str.substring( 7 ));
  27.         int i = ii.intValue();
  28.         if ( i >= 0 && i < PARTS_MAX ){
  29.                 mat[ i ].setValue( color );
  30.             no[ i ].setValue( colorno );
  31. //                System.out.println( i );
  32.         }
  33.     }
  34.     }
  35.  
  36.     public void initialize (){
  37.     String str;
  38.     for( int i = 0; i < PARTS_MAX; i++ ){
  39.         str = "mat" + i;
  40.         mat[ i ] = ( SFColor ) getEventOut( str ) ;
  41.         str = "no" + i;
  42.         no[ i ] = ( SFInt32 ) getEventOut( str ) ;
  43.     }
  44.     // get currentColor
  45.     color = (SFColor) getField( "currentColor" );
  46.     colorno = (SFInt32) getField( "currentColorNo" );
  47.  
  48. //        System.out.println( "init" );
  49.     }
  50. }
  51.  
  52.  
  53.